//==========================================================================//
// 菜单的效果

$(document).ready(function(){
	/**随机数是为了解决jquery缓存的问题*/
	var r = parseInt(1000000*Math.random());
	$("#main-left").load("left.shtml?r="+r, function() {
		menu();
	});
	$("#main-header").load("header.shtml?r="+r, function() {
		header();
	});
	$(".hint-close").on("click",closehint);
	if(typeof(employeeId)!='undefined'&&employeeId!=null&&employeeId!=''){
		//window.open(ctp+"/userController/userAdd.shtml", "right", "fullscreen=0");
	}	
    $(window).resize(function(){  
       var height=	$(window).height()-50;
       var width=	$(window).width()-60;
			   $(".ifs").css("width",width+"px");
			  $(".ifs").css("height",height+"px");
    });

	
});

var maxw = 250; // 最大宽度
var minw = 50; // 最小宽度
var time = 100; // 动画时间
var lock = true; // 锁定菜单
function menu() {
	$(".lock").on("click", menuchk);
	$(".max-menu").on("mouseenter", maxmenu);
	$("#main-left").on("mouseleave", minmenu);
	$(".max-menu li").on("click", tree);
	$(".tree li").not(".tree2").on("click", urlpage);
	/*$(".tree li").not(".tree2").on("click", second);
	$(".tree2 li").on("click", urlpage);*/
	$(".second").perfectScrollbar();
	$(".logo .title span").hide();

};

function menuchk() {
	if (lock) {
		lock = false;
		$(".lock").removeClass("i-menu");
		$(".lock").addClass("i-menu-lock");
	} else {
		lock = true;
		$(".lock").removeClass("i-menu-lock");
		$(".lock").addClass("i-menu");
	}
	;
};

function maxmenu() {
	var w;
	if (lock) {
		w = maxw;
		$(".system-name").hide(time);
		$(".logo .title span").show();
	} else {
		w = minw;
		$(".logo .title span").hide();
	}
	$(".second").hide();
	$(".second").css({
		left : w
	});
	$(".main-max-menu").stop(false, true).animate({
		width : w
	}, time, "easeInCirc");
	$(".max-menu").off("mouseenter", maxmenu);
	
};

function minmenu() {
	$(".system-name").show(time);
	$(".second").hide();
	$(".main-max-menu").stop(false, true).animate({
		width : minw
	}, time, "easeInCirc", function() {
		$(".max-menu").on("mouseenter", maxmenu);
	});
	$(".logo .title span").hide();
};

function urlpage() {
	var _url = $(this).data('url');
	var _fun = $(this).data('fun');
	var _id =$(this).data('id');
	if (_url !== null) {
//		$("#main-page").load(mp + _url, function() {
//			init();
//		});
		var url = ctp + _url;
		if(_url.indexOf("?")>0){
			url+="&";
		}else{
			url+="?";
		}
		url+="param.moduleId="+_id;
		alert(url);
		window.open(url, "right", "fullscreen=0");
	};
	minmenu();
};

/* 二级菜单 */
function tree() {
	$(".second").hide();
	var _s = $(this).data('s');
	var _url = $(this).data('url');
	var _group = $(this).data('group');
	$(".max-menu li").removeClass("active");
	$(this).addClass("active");
	if (_s == "off") {
		//$("#main-page").load(_url);
		window.open(_url, "right", "fullscreen=0");
	} else {
		$("#" + _group).show();
		$(".second p").text($(this).text()); // 放文字
		$("#" + _group+" .tree li").eq(0).find(".tree2").show();
	}
	;
};

/* 三级菜单 */
function second() {
	$(this).siblings().removeClass("active");
	$(this).siblings().find(".tree2").hide();
	$(this).siblings().find(".arrow").removeClass("i-arrow-down");
	$(this).find(".tree2").slideToggle();
	$(this).addClass("active");
	$(this).find(".arrow").addClass("i-arrow-down");

};

// ==========================================================================//
/* 头部头像 */
function header() {
	$(".user-img").on('mouseenter', function() {
		$(".system-info li.hide").show(200);
	});
	$(".system-info").on('mouseleave', function() {
		$(this).find(".hide").hide(200);
	});

	$(".system-info li.mate").hover(function() {
		var _hint = $(this).children().data('hint');
		if ($(this).find(".hint").length < 1) {
			$(this).append("<div class='hint'>" + _hint + "</div>");
			$(this).find(".hint").css({
				marginTop : "-100%"
			});
			$(this).find(".hint").stop().animate({
				marginTop : 0
			}, 500);
		}
		;
	}, function() {
		$(".hint").remove();
	});
	
	$(".f-close").on('click', function() {
		window.location.href = ctp+"/loginController/loginout.shtml";
	});
	$("#f-PWD").on('click', changePWD);
	$("#f-OPR").on('click', changeOPRPWD);
	$(".f-msg").on('click', function() {
		var url = ctp+"/system/msg/sysmsg.shtml";
		var w = $(window).width();
		$.layer({
		    type : 2,
		    title : '系统消息',
		    zIndex : 1000,
		    iframe : {src : url},
		    maxmin: true,
		    area : [(w*0.75)+'px' , ($(window).height() - 120) + 'px'],
		    offset : ['55px','']
		});
	});

};
function closehint(){
	$(".m-hint").hide();
}

function init(employeeId){
	if(employeeId=='null')
	window.open(ctp+"/userController/userAdd.shtml", "right", "fullscreen=0");
}
function showTip(){
	var _s = $(this).data('title');
}

function logout(){
	window.location.href = ctp+"/loginController/loginout.shtml";
}

function changePWD(){
	var url = "";
	if(userType=="1"){
		url = ctp +"/userController/userPassWordUpdate.shtml";
	}else if(userType=="2"){
		url = ctp +"/employeeController/employeePassWrodUpdate.shtml";
	}else if(userType=="3"){
		url=ctp+"/developerController/developerPassWord.shtml";
	}
	
	var pagei = $.layer({
	    type: 2,
	    title: '修改登录密码',
	    area : ['550px' , '350px'],
	    shadeClose: false,
	    closeBtn: [1, true],
	    offset: [($(window).height() - 200)/2+'px', ''], //上下垂直居中  
	    border: [0],
	    shade : [0.9, '#000'],
	    iframe: {src: url}
	});
}
function changeOPRPWD(){
	var pagei = $.layer({
	    type: 2,
	    title: '修改操作密码',
	    area : ['550px' , '350px'],
	    shadeClose: false,
	    closeBtn: [1, true],
	    offset: [($(window).height() - 200)/2+'px', ''], //上下垂直居中  
	    border: [0],
	    shade : [0.9, '#000'],
	    iframe: {src: ctp + '/system/user/jumpChangeOPRPWD.shtml'}
	});
}
function tk(){
	minmenu();
}
